﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace limpalex.bbparser.Tree
{
    class Root : INode, IEnumerable<INode>
    {
        private readonly IList<INode> _nodes = new List<INode>();

        public void GetText(StringBuilder buffer, Parser parser)
        {
            if (NodesCount == 0)
                return;
            
            foreach (var node in _nodes)
            {
                node.GetText(buffer, parser);
            }
        }

        public NodeType Type
        {
            get { return NodeType.Root; }
        }

        public void AddNode(INode node)
        {
            if ( node != null)
                _nodes.Add(node);
        }

        public int NodesCount
        {
            get { return _nodes.Count; }
        }

        public IEnumerator<INode> GetEnumerator()
        {
            return _nodes.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public INode this[int n]
        {
            get { return _nodes[n]; }
            set { _nodes[n] = value; }
        }
    }
}
